package pub.guoxin.oops.auth.vo;

import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import pub.guoxin.oops.enums.Authority;
import pub.guoxin.oops.model.User;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.List;

/**
 * Created by stephan on 20.03.16.
 */

@ApiModel
@AllArgsConstructor
@NoArgsConstructor
@Data
public class LoginUserToken implements Serializable {

    private static final long serialVersionUID = 1250166508152483573L;

    private String id;

    @ApiModelProperty(value = "公司Id", required = true, hidden = true)
    private String companyId;

    @NotNull
    @Size(min = 2, max = 50)
    @ApiModelProperty(value = "名称", required = true, hidden = true)
    private String name;

    @NotNull
    @Size(min = 11, max = 11)
    @ApiModelProperty(value = "手机号", required = true, hidden = true)
    private String username;

    @ApiModelProperty(value = "权限", required = true, hidden = true)
    private List<Authority> authorities = Lists.newArrayList();

    @ApiModelProperty(value = "密钥", required = true)
    private String token;

    @ApiModelProperty(value = "是否第一次登陆", required = true)
    private Boolean firstLogin;

    public LoginUserToken(User user, String token) {
        this.id = user.getId();
        this.authorities = user.getAuthorities();
        this.companyId = user.getCompanyId();
        this.name = user.getFirstname();
        this.username = user.getMobile();
        this.token = token;
        this.firstLogin = user.getFirstLogin();
    }

}
